package com.czk.suspend;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;

/**
 * 全部流程实例的激活与挂起
 * 流程被挂起后，不允许新的流程
 * @Author ChenZhangKun
 * @Date 2020/9/11 9:15
 */
public class SuspendProcessInstance {
    public static void main(String[] args) {
        // 得到引擎
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 执行查询
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        // 设置查询条件
        ProcessDefinition holiday = processDefinitionQuery.processDefinitionKey("holiday").singleResult();
        // 得到所有的实例是否都暂停
        boolean suspended = holiday.isSuspended();
        if (suspended){
            // 是暂停
            // 执行激活
            String id = holiday.getId();
            repositoryService.activateProcessDefinitionById(id,true,null);
            System.out.println(holiday.getName()+"实例被激活");
        }else {
            repositoryService.suspendProcessDefinitionById(holiday.getId(),true,null);
            System.out.println(holiday.getName()+"实例被挂起");
        }

    }
}
